import React, { Component } from 'react';
import { View, Text, Image, TouchableOpacity, } from 'react-native';

import moment from 'moment';

var Dimensions = require('Dimensions');
var { width, height } = Dimensions.get('window');


class ExpendListItem extends Component {

    render() {
        return (
            <TouchableOpacity  style={{ flexDirection: 'row', borderBottomColor: 'gray', borderBottomWidth: 0.5 ,backgroundColor:'white'}}
                onPress={(rowData) => this.props.itemClick(this.props.rowData)}
            >
                <Image source={{ uri: this.iconImgName(this.props.rowData.item) }}
                    style={{ top: 10, left: 10, marginRight: 15, width: 40, height: 40 }}
                />
                <View>
                    <View flexDirection='row'>
                        <Text style={{ marginTop: 10, marginBottom: 10, marginRight: 5 }}>{this.props.rowData.item.tempName}</Text>

                        {this.DiDiImg(this.props.rowData.item)}
                    </View>
                    <Text style={{ marginBottom: 10 }}>{this.formatDate(this.props.rowData.item)}</Text>
                    {this.remarkView(this.props.rowData.item)}
                </View>
                <View style={{ marginTop: 10, marginRight: 40, flex: 1, alignItems: 'flex-end'}}>
                    <Text style={{marginBottom:10}}>CNY</Text>
                    <Text style={{marginBottom:10,color:'red',alignSelf:'flex-end'}}>{this.props.rowData.item.amount}</Text>
                </View>
            </TouchableOpacity>
        );
    }

    DiDiImg(item) {

        if (item.ditchType === '0') {
            return <Image source={{ uri: '滴滴-small' }}
                style={{ marginTop: 10, width: 20, height: 20 }}
            />
        }
        return null
    }

    formatDate(item) {

        switch (item.tempType) {
            case 4://手机费
            case 5://业务招待费
            case 6://交通补贴
            case 7://出差补贴
            case 8://团队建设费
            case 10://工作餐补贴
            case 11://办公用品费
            case 12://车辆保险
            case 14://车辆维修费
            case 17://礼品费
            case 21://体检费
                return moment(item.startDate).format("YYYY-MM-DD");
                break;
            default:
                return moment(item.startDate).format("YYYY-MM-DD HH:mm:ss");
                break;
        }

    }

    remarkView(itemData) {

        if (itemData.remark.length > 0) {

            return <Text  numberOfLines={1} style={{ marginBottom: 10,maxWidth:width - 75}}>{this.props.rowData.item.remark}</Text>
        }

        return <Text />
    }


    iconImgName(itemData) {

        var array = [{ "name": "", "imageName": "", "type": "1" },
        { "name": ("市内交通费"), "imageName": "市内交通", "type": "1" },
        { "name": ("外埠交通费"), "imageName": "外埠交通", "type": "2" },
        { "name": ("住宿费"), "imageName": "住宿费", "type": "3" },
        { "name": ("手机费"), "imageName": "手机费", "type": "4" },
        { "name": ("业务招待费"), "imageName": "业务招待费", "type": "5" },
        { "name": ("交通补贴"), "imageName": "交通补贴", "type": "9" },
        { "name": ("出差补贴"), "imageName": "出差补贴", "type": "8" },
        { "name": ("团队建设费"), "imageName": "团队建设费", "type": "6" },
        { "name": ("外部劳务费"), "imageName": "外部劳务费", "type": "7" },
        { "name": ("工作餐补贴"), "imageName": "工作餐补贴", "type": "10" },
        { "name": ("办公用品费"), "imageName": "办公用品费", "type": "11" },
        { "name": ("车辆保险费"), "imageName": "车辆保险费", "type": "12" },
        { "name": ("车辆使用费"), "imageName": "车辆使用", "type": "13" },
        { "name": ("车辆维修费"), "imageName": "车辆维修费", "type": "14" },
        { "name": ("房租费用"), "imageName": "房租费用", "type": "15" },
        { "name": ("会议费"), "imageName": "会议费", "type": "16" },
        { "name": ("礼品费"), "imageName": "礼品费", "type": "17" },
        { "name": ("培训费"), "imageName": "培训费", "type": "18" },
        { "name": ("汽车租赁费"), "imageName": "汽车租赁费", "type": "19" },
        { "name": ("私车公用油费"), "imageName": "私车公用费", "type": "20" },
        { "name": ("体检费"), "imageName": "体检费", "type": "21" },
        { "name": ("油卡充值费"), "imageName": "油卡充值费", "type": "22" },
        { "name": ("其他费用"), "imageName": "其他费用", "type": "23" }];

        var obj = array[itemData.tempType]

        return obj.imageName;

    }
}

export default ExpendListItem;

